package com.example.animaldoctor03;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;

























import com.example.animaldoctor03.R;

import commonClass.ADAQuerySymptomsCategorieByAnimalIDAction1offz;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.Symptoms;
import Modle.disease.SymptomsCategorie;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class ZhengZhuangFZ extends Activity {
	

	private ListView listofzhengzhuangfz = null;
	private RadioGroup radiogroupofzhengzhuangfz = null;
	
	private String animalIDifZZFZ = "01371054603" ;
	private ArrayList<Object> resultListofZZFZ = null;
	
	
	private RadioButton checkedbuttonoffirst = null;
	
	private void initElemofZZFZ (){
		
		setContentView(R.layout.zhengzhuangfz);
		
		radiogroupofzhengzhuangfz = (RadioGroup)findViewById(R.id.radiogroupofzhengzhuangfz);
		
		//默认跳转过来就是第一个被选中
		radiogroupofzhengzhuangfz.check(R.id.radiobuttonofzhengzhuangfz1);
		
		checkedbuttonoffirst = (RadioButton)radiogroupofzhengzhuangfz.findViewById(radiogroupofzhengzhuangfz.getCheckedRadioButtonId());
		
		radiogroupofzhengzhuangfz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				
				checkedbuttonoffirst = (RadioButton) radiogroupofzhengzhuangfz.findViewById(checkedId);
				if(checkedId == R.id.radiobuttonofzhengzhuangfz1){
					
				}
				else{
					Intent intentofzhengzhuangfz = new Intent(ZhengZhuangFZ.this , ZhengZhuangFZ2.class);
					startActivity(intentofzhengzhuangfz);
					finish();
				}
				
			}
		});
		listofzhengzhuangfz = (ListView)findViewById(R.id.listofzhengzhuangfz);
		
	}
	private ArrayList<Object> assemblyofZZFZ() {

		ArrayList<Object> list = new ArrayList<Object>();

		list.add(animalIDifZZFZ);
		// Integer i = new Integer(10);
		// list.add(i);

		return list;
	}
	private void bindingofZZFZ(final ArrayList<Object> list){
	try{	
		String[] resultofZZFZ1 = new String[list.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < list.size(); i++) {
			
			
			//haiyouwenti
			resultofZZFZ1[i] = ((SymptomsCategorie) list.get(i)).getSymptomsCategorieName();
		}
		ArrayAdapter<String> arrayAdapterofResult = new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_1, resultofZZFZ1);
		listofzhengzhuangfz.setAdapter(arrayAdapterofResult);
		
		 listofzhengzhuangfz.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view, int position,
						long id) {
					// TODO Auto-generated method stub
					Bundle bundleofZhengZhuangFZ = new Bundle();
					bundleofZhengZhuangFZ.putSerializable("shuju", (Serializable) list.get(position));
					Intent intent = new Intent (ZhengZhuangFZ.this , IllnessDetail.class);
					intent.putExtras(bundleofZhengZhuangFZ);
					startActivity(intent);
					finish();
				}
		 
	

				
			 
		 });
		 }catch(NullPointerException e){
			 
			 android.app.AlertDialog.Builder builderofZZFZ = new AlertDialog.Builder(ZhengZhuangFZ.this);
			 builderofZZFZ.setMessage("无数据，请用其他功能");
			 builderofZZFZ.create().show();
		 }
		
	}
	@Override
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		initElemofZZFZ();
		ArrayList<Object> parasListofZZFZ = assemblyofZZFZ();
		
		final ArrayList<Object> resultListTofZZFZ = null;
		
		ADAQuerySymptomsCategorieByAnimalIDAction1offz iActionofZZFZ = new ADAQuerySymptomsCategorieByAnimalIDAction1offz();
		
		FunctionDispatcher functionDispacherofZZFZ = new FunctionDispatcher();
		
		functionDispacherofZZFZ.exceute(RemoteActionsName.QuerySymptomsCategorieByAnimalID, parasListofZZFZ, iActionofZZFZ, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
				try{
				Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
				ZhengZhuangFZ.this.resultListofZZFZ = resultList;
				bindingofZZFZ(resultList);
				}catch(NullPointerException e){
					android.app.AlertDialog.Builder builderofZZFZf = new AlertDialog.Builder(ZhengZhuangFZ.this);
					builderofZZFZf.setMessage("无返回值  , 请用其他功能");
					builderofZZFZf.create().show();
				}
			}
		},this);

	}

}